import { listInterfaceInfoByPage } from '@/services/phxz-backend/interfaceInfoController';
import { PageContainer } from '@ant-design/pro-components';
import { List, message } from 'antd';
import React, { useEffect, useState } from 'react';
//import InterfaceInfo = API.InterfaceInfo;

type PaginationPosition = 'top' | 'bottom' | 'both';

type PaginationAlign = 'start' | 'center' | 'end';

const Start: React.FC = () => {
  const [position, setPosition] = useState<PaginationPosition>('bottom');
  const [align, setAlign] = useState<PaginationAlign>('center');
  const [list, setList] = useState<API.InterfaceInfo[]>([]);
  const [total, setTotal] = useState<number>(0);
  const loadData = async (current = 1, pageSize = 5) => {
    try {
      const res = await listInterfaceInfoByPage({
        current,
        pageSize,
      });
      if (res.data) {
        setList(res?.data?.records ?? []);
        setTotal(res.data.total || 0);
      }
    } catch (error: any) {
      message.error('请求失败:' + error.message);
    }
  };
  useEffect(() => {
    loadData();
  }, []);
  return (
    <PageContainer>
      <List
        pagination={{
          showTotal: (total) => {
            return '总数:' + total;
          },
          position,
          align,
          total: total,
          pageSize: 5,
          onChange: (page, pageSize) => {
            loadData(page, pageSize);
          },
        }}
        dataSource={list}
        renderItem={(item) => (
          <List.Item>
            <List.Item.Meta
              title={<a href={'http://localhost:8000/interface/' + item.id}>{item.name}</a>}
              description={item.description}
            />
          </List.Item>
        )}
      />
    </PageContainer>
  );
};

export default Start;
